//+--------------------------------------------------------------------------------
//| Copyright (c) 2012 - 2013 ### an.vuongngocduy
//| This file is a part of Compact Game Engine (CGE)
//+--------------------------------------------------------------------------------
#include "cgeEngine.h"
#include "cgeCanvasWin32.h"
#include "cgeRendererOGL.h"

namespace cge
{	
	//=========================================================================================
	Engine::Engine() :
		mCanvas(null),
		mSysMsgDistribute(null)
	{
		mSysMsgDistribute = &CanvasWin32::WindowMessageDispatch;
	}

	//=========================================================================================
	Engine::~Engine()
	{}

	//=========================================================================================
	Canvas* Engine::CreateCanvas(ERendererDriver driver)
	{
		if(mCanvas == null)
		{
			mCanvas = new CanvasWin32();
			mCanvas->Setup("This is just a test", Vector2u(100, 100), Dimension2u(800, 600), false);
			
			if(driver == RendererDriver::OpenGL)
				mCanvas->mRender = new RendererOGL();
			
			mCanvas->mRender->Initialize(mCanvas);
		}
		return mCanvas;
	}

	//=========================================================================================
	void Engine::Run()
	{
		mCanvas->Show();
		bool isFinished = false;
		while(!isFinished)
		{
			isFinished = mSysMsgDistribute(null);
			mCanvas->Render();
		}
	}


	//=========================================================================================
}